import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:flutter/services.dart';
// import 'package:wechat_assets_picker/wechat_assets_picker.dart';

// import 'package:wechat_camera_picker/wechat_camera_picker.dart';
import 'package:xin_he/page/mine/xin_he_apply_sale_after/xin_he_apply_back_goods_and_money/xin_he_drag_sort_view.dart';
import 'package:xin_he/page/mine/xin_he_apply_sale_after/xin_he_apply_back_goods_and_money/xin_he_upload_images_model.dart';
import 'package:get/get.dart' hide MultipartFile, FormData;

import '../xin_he_apply_sale_after_view.dart';
import 'xin_he_apply_back_goods_and_money_state.dart';

class XinHeApplyBackGoodsAndMoneyLogic extends GetxController {
  final XinHeApplyBackGoodsAndMoneyState state = XinHeApplyBackGoodsAndMoneyState();


  List<ImageBean> imageList = [];
  final List<File> imageFiles = [];
  int moveAction = MotionEvent.actionUp;
  late bool _canDelete;
  late List selectedAssets = [];
  late List assetList = [];
  String imageUrlString = "";

  final type = SaleAfterType.unknown.obs;
  final title = ''.obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    type.value  = Get.arguments;
    if(type.value == SaleAfterType.backMoneyAndGoods){
      title.value = '申请退货退款';
    }else if(type.value == SaleAfterType.backMoney){
      title.value = '申请退款';

    }else if(type.value == SaleAfterType.changeGoods){
      title.value = '申请换货';

    }else {

    }

  }


  /// 回收键盘
  void keyboardBack() {
    if (Get.focusScope?.hasPrimaryFocus == true) {
      Get.focusScope?.unfocus();
    }
  }

  void setFeedbackText(String value) {
    state.feedStr = value;
    state.textNum.value = value.length;
  }

  void setMoneyText(String value) {
    state.moneyAmount = value;
  }

  bool get canDelete => _canDelete;

  set canDelete(bool value) {
    _canDelete = value;
    update();
  }

  void updateButtonType(int value) {
    state.selectFeedbackType = value;
    update();
  }

  void deleteImageUpdate(int value) async {
    assetList.removeAt(value);
    imageFiles.clear();
    for (var entity in assetList) {
      File? imgFile = await entity.file;
      if (imgFile != null) {
        imageFiles.add(imgFile);
      }
    }
    imageList = PictureUtils.getImageBean(imageFiles);
    update();
  }

  selectPictures(BuildContext context) async {
    // final List<AssetEntity>? entityList = await AssetPicker.pickAssets(context,
    //     pickerConfig: AssetPickerConfig(
    //       // selectedAssets: selectedAssets,
    //       maxAssets: 3 - imageFiles.length,
    //       requestType: RequestType.image,
    //     ));
    // if (entityList == null) return;
    // selectedAssets.addAll(entityList);
    // //遍历
    // for (var entity in entityList) {
    //   File? imgFile = await entity.file;
    //   if (imgFile != null) {
    //     imageFiles.add(imgFile);
    //   }
    // }
    // imageList = PictureUtils.getImageBean(imageFiles);
    // update();
  }


}
